public class test1 {
    //力扣  238 除自身以外数组的乘积
    public int[] productExceptSelf(int[] nums) {
        int n =nums.length;
        int[] dpf = new int[n];
        int[] dpg = new int[n];
        int[] answer = new int[n];
        //细节，一定不能忘
        dpf[0] = 1;
        dpg[n-1] = 1;
        //预设前缀积数组和后缀积数组
        for(int i = 1;i<n;i++){
            dpf[i] = dpf[i-1] * nums[i-1];
        }
        for(int i = n-2;i>=0;i--){
            dpg[i] = dpg[i+1] * nums[i+1];
        }
        //使用数组
        for(int i = 0;i<n;i++){
            answer[i] = dpf[i] * dpg[i];
        }
        return answer;
    }
}
